﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.Record;
using TyMES.Model;

namespace TyMES.ViewModel.Record.MachineStatusRecordVMs
{
    public partial class MachineStatusRecordListVM : BasePagedListVM<MachineStatusRecord_View, MachineStatusRecordSearcher>
    {
        
        protected override IEnumerable<IGridColumn<MachineStatusRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<MachineStatusRecord_View>>{
                
                this.MakeGridHeader(x => x.MachineStatusRecord_factoryCode).SetTitle(@Localizer["Page.工厂编码"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_lineCode).SetTitle(@Localizer["Page.产线编码"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_stationCode).SetTitle(@Localizer["Page.工位编码"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_machineCode).SetTitle(@Localizer["Page.机台编码"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_machineStatusCode).SetTitle(@Localizer["Page.机台状态编码"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_acquistCode).SetTitle(@Localizer["Page.数采设备编码"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_machineStatusBegin).SetTitle(@Localizer["Page.接收时间"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_machineStatusEnd).SetTitle(@Localizer["Page.处理时间"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_editTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_StatusType).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_uploadflag).SetTitle(@Localizer["Page.上传标识"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.MachineStatusRecord_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<MachineStatusRecord_View> GetSearchQuery()
        {
            var query = DC.Set<MachineStatusRecord>()
                
                .CheckContain(Searcher.FactoryCode, x=>x.FactoryCode)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckContain(Searcher.StationCode, x=>x.StationCode)
                .CheckContain(Searcher.MachineCode, x=>x.MachineCode)
                .CheckContain(Searcher.MachineStatusCode, x=>x.MachineStatusCode)
                .CheckContain(Searcher.AcquistCode, x=>x.AcquistCode)
                .CheckContain(Searcher.MachineStatusBegin, x=>x.MachineStatusBegin)
                .CheckContain(Searcher.MachineStatusEnd, x=>x.MachineStatusEnd)
                .CheckContain(Searcher.EditTime, x=>x.EditTime)
                .CheckContain(Searcher.StatusType, x=>x.StatusType)
                .CheckEqual(Searcher.Uploadflag, x=>x.Uploadflag)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new MachineStatusRecord_View
                {
				    ID = x.ID,
                    
                    MachineStatusRecord_factoryCode = x.FactoryCode,
                    MachineStatusRecord_lineCode = x.LineCode,
                    MachineStatusRecord_stationCode = x.StationCode,
                    MachineStatusRecord_machineCode = x.MachineCode,
                    MachineStatusRecord_machineStatusCode = x.MachineStatusCode,
                    MachineStatusRecord_acquistCode = x.AcquistCode,
                    MachineStatusRecord_machineStatusBegin = x.MachineStatusBegin,
                    MachineStatusRecord_machineStatusEnd = x.MachineStatusEnd,
                    MachineStatusRecord_editTime = x.EditTime,
                    MachineStatusRecord_StatusType = x.StatusType,
                    MachineStatusRecord_uploadflag = x.Uploadflag,
                    MachineStatusRecord_CreateTime = x.CreateTime,
                    MachineStatusRecord_UpdateTime = x.UpdateTime,
                    MachineStatusRecord_CreateBy = x.CreateBy,
                    MachineStatusRecord_UpdateBy = x.UpdateBy,
                })
                .OrderByDescending(x => x.ID);
            return query;
        }

        
    }
    public class MachineStatusRecord_View: MachineStatusRecord
    {
        
        public string MachineStatusRecord_factoryCode { get; set; }
        public string MachineStatusRecord_lineCode { get; set; }
        public string MachineStatusRecord_stationCode { get; set; }
        public string MachineStatusRecord_machineCode { get; set; }
        public string MachineStatusRecord_machineStatusCode { get; set; }
        public string MachineStatusRecord_acquistCode { get; set; }
        public string MachineStatusRecord_machineStatusBegin { get; set; }
        public string MachineStatusRecord_machineStatusEnd { get; set; }
        public string MachineStatusRecord_editTime { get; set; }
        public string MachineStatusRecord_StatusType { get; set; }
        public bool? MachineStatusRecord_uploadflag { get; set; }
        public DateTime? MachineStatusRecord_CreateTime { get; set; }
        public DateTime? MachineStatusRecord_UpdateTime { get; set; }
        public string MachineStatusRecord_CreateBy { get; set; }
        public string MachineStatusRecord_UpdateBy { get; set; }

    }

}